#ifndef THINK_THINK_PROCESS_PIPES_PIPES_H
#define THINK_THINK_PROCESS_PIPES_PIPES_H

static char* think_process_pipes_pipes =
	"\n"
	"// +----------------------------------------------------------------------\n"
	"// | ThinkPHP [ WE CAN DO IT JUST THINK ]\n"
	"// +----------------------------------------------------------------------\n"
	"// | Copyright (c) 2006~2015 http://thinkphp.cn All rights reserved.\n"
	"// +----------------------------------------------------------------------\n"
	"// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )\n"
	"// +----------------------------------------------------------------------\n"
	"// | Author: yunwuxin <448901948@qq.com>\n"
	"// +----------------------------------------------------------------------\n"
	"\n"
	"namespace think\\process\\pipes;\n"
	"\n"
	"abstract class Pipes\n"
	"{\n"
	"\n"
	"    /** @var array */\n"
	"    public $pipes = [];\n"
	"\n"
	"    /** @var string */\n"
	"    protected $inputBuffer = \'\';\n"
	"    /** @var resource|null */\n"
	"    protected $input;\n"
	"\n"
	"    /** @var bool */\n"
	"    private $blocked = true;\n"
	"\n"
	"    const CHUNK_SIZE = 16384;\n"
	"\n"
	"    /**\n"
	"     * 返回用于 proc_open 描述符的数组\n"
	"     * @return array\n"
	"     */\n"
	"    abstract public function getDescriptors();\n"
	"\n"
	"    /**\n"
	"     * 返回一个数组的索引由其相关的流，以防这些管道使用的临时文件的文件名。\n"
	"     * @return string[]\n"
	"     */\n"
	"    abstract public function getFiles();\n"
	"\n"
	"    /**\n"
	"     * 文件句柄和管道中读取数据。\n"
	"     * @param bool $blocking 是否使用阻塞调用\n"
	"     * @param bool $close    是否要关闭管道，如果他们已经到达 EOF。\n"
	"     * @return string[]\n"
	"     */\n"
	"    abstract public function readAndWrite($blocking, $close = false);\n"
	"\n"
	"    /**\n"
	"     * 返回当前状态如果有打开的文件句柄或管道。\n"
	"     * @return bool\n"
	"     */\n"
	"    abstract public function areOpen();\n"
	"\n"
	"    /**\n"
	"     * {@inheritdoc}\n"
	"     */\n"
	"    public function close()\n"
	"    {\n"
	"        foreach ($this->pipes as $pipe) {\n"
	"            fclose($pipe);\n"
	"        }\n"
	"        $this->pipes = [];\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 检查系统调用已被中断\n"
	"     * @return bool\n"
	"     */\n"
	"    protected function hasSystemCallBeenInterrupted()\n"
	"    {\n"
	"        $lastError = error_get_last();\n"
	"\n"
	"        return isset($lastError[\'message\']) && false !== stripos($lastError[\'message\'], \'interrupted system call\');\n"
	"    }\n"
	"\n"
	"    protected function unblock()\n"
	"    {\n"
	"        if (!$this->blocked) {\n"
	"            return;\n"
	"        }\n"
	"\n"
	"        foreach ($this->pipes as $pipe) {\n"
	"            stream_set_blocking($pipe, 0);\n"
	"        }\n"
	"        if (null !== $this->input) {\n"
	"            stream_set_blocking($this->input, 0);\n"
	"        }\n"
	"\n"
	"        $this->blocked = false;\n"
	"    }\n"
	"}\n"
	"\n"
;
#endif